<template>
  <div class="common-page f-c">
    <el-form inline>
      <el-form-item label="课程类型">
        <el-select v-model="searchParams.category_id" filterable placeholder="可搜索选择" @change="changeCategory">
          <el-option v-for="item in categoryList" :key="item.id" :value="item.id" :label="item.name" />
        </el-select>
      </el-form-item>
      <el-form-item label="课程名称">
        <el-select v-model="searchParams.course_id" filterable placeholder="可搜索选择" @change="changeCategory">
          <el-option v-for="item in courseList" :key="item.id" :value="item.id" :label="item.course_name" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="margin-left: 15px" @click="onSearch">搜索</el-button>
        <el-button type="primary" style="margin-left: 15px" @click="onReset">清除</el-button>
      </el-form-item>
    </el-form>
    <!--    <div class="button-list2 f-r a-c" style="height: 74px">-->
    <!--      <el-button type="danger" @click="onAdd">添加</el-button>-->
    <!--    </div>-->
    <div class="table-box">
      <el-table
        v-loading="loading"
        style="width: 100%"
        height="100%"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" align="center" label="序号" />
        <el-table-column
          v-for="item in columns"
          :key="item.prop"
          :prop="item.prop"
          :label="item.label"
          align="center"
        />
        <!--        <el-table-column label="操作" fixed="right" width="120px">-->
        <!--          <template slot-scope="scope">-->
        <!--            <el-button-->
        <!--              type="text"-->
        <!--              style="color: #0DB493"-->
        <!--              @click="onEdit(scope.row)"-->
        <!--            > 编辑-->
        <!--            </el-button>-->

        <!--            <el-button-->
        <!--              type="text"-->
        <!--              style="color: red"-->
        <!--              @click="onDelete(scope.row)"-->
        <!--            > 删除-->
        <!--            </el-button>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
    </div>
    <PageAdd ref="PageAddRef" @save="emitSave" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import PageAdd from './page-add'
import { http } from '@/api'
import { mapGetters } from 'vuex'
export default {
  name: 'Page',
  components: {
    PageAdd
  },
  mixins: [crud],
  computed: {
    ...mapGetters(['categoryList'])
  },
  data() {
    return {
      searchParams: {
        category_id: '',
        course_id: ''
      },
      courseList: [],
      request: http.ap,
      columns: [
        { prop: 'course.course_name', label: '课程名称' },
        { prop: 'teacher.teacher_name', label: '开课老师' },
        { prop: 'student.student_name', label: '评价学生' },
        { prop: 'score', label: '评分(最高5分)' },
        { prop: 'desc', label: '评语' },
        { prop: 'created_at', label: '评价时间' }
      ]
    }
  },
  methods: {
    changeCategory(val) {
      http.course.list({
        category_id: val
      }).then(res => {
        this.courseList = res
      })
    }
  }
}
</script>

<style scoped lang="scss">
.common-page {
  height:  100%;
}
</style>
